<template>
	<skeleton :loading="loading">
		<view class="content"
			style="background: linear-gradient(180deg, #60a3fe 0%, #F3F6F6 766rpx,rgba(243, 246, 246, 1) 100%) no-repeat">
			<view class="steps" v-if="status == 5 || status == 6" style="align-items: center;padding-left: 50rpx;">
				<image :src="status == 5 ? `../../../static/img/success.png` : `../../../static/img/error.png`" mode="">
				</image>
				<view class="">
					<view class="status">{{ status == 5 ? '服务完成' : '已取消' }}</view>
					<view class="status_msg">{{ status == 5 ? '该订单已完成' : '该订单已取消' }}</view>
				</view>
			</view>
			<view class="steps" v-else style="align-items: center;padding: 48rpx 58rpx 32rpx 58rpx;">
				<view class="step" v-for="(item, index) in steps" :key="index">
					<view class="" style="text-align: center; width: 112rpx;">
						<view class="stepImg">
							<image :src="item.src" mode=""></image>
						</view>
						<view class="stepTitle">{{ item.msg }}</view>
					</view>
					<text class=""
						:style="index < 3 ? 'width: 70rpx;height: 2rpx;background: rgba(255, 255, 255, 0.6); margin-top:48rpx' : ''"></text>
				</view>
			</view>
			<view class="project">
				<view class="title">
					<view class="titleIcon">
						<image src="../../../static/icon/order/1.png" mode=""></image>
					</view>
					<view class="titleMsg">{{ list.serviceName }}</view>
					<view class="type" style="width: 160rpx; text-align: center;	">{{ showStatus() }}</view>
				</view>

				<view class="pro_detaile" style="display: flex; margin-bottom: 24rpx; " v-for="(item, index) in service"
					:key="index">
					<view class="" style="margin-right: 16rpx; color: #333333; width: 120rpx;white-space:nowrap;">
						{{ item.title }}:
					</view>
					<view class=""
						style="display: flex; align-items: flex-end; flex-wrap:wrap; color: #666666;width: 100%;position: relative;">
						<view class="mabye" v-if="index == 0" style=" margin-right: 16rpx;width: 73%;">
							{{ item.value[0] }}
						</view>
						<view class="mabye" v-else style=" margin-right: 16rpx;">{{ item.value[0] }}
						</view>
						<text class="other my" v-if="index == 2||index == 0" type="primary"
							@click="handleCopy(item.value[0])">复制</text>

						<view class="" style=" margin-right: 16rpx;">{{ item.value[1] || '' }}</view>
						<view style=" margin-right: 16rpx;" class="">{{ item.value[2]  || ''}}
						</view>
						<view class="other" v-if="index == 3" @click="seeOther">查看资料</view>
					</view>
				</view>
			</view>
			<!-- 			<view class="nursingP">
					<view class="title">
						<view class="titleIcon">
							<image src="../../../static/icon/order/2.png" mode=""></image>
						</view>
						<view class="titleMsg">护理必备</view>
					</view>
				</view> -->
			<!-- 	<view class="nursingP" style="color: #3c8eff;">
					<view class="" style="width: 216rpx; text-align: center;">
						{{ list.nurseOrderInfoBagVo ? '耗材包×' + list.nurseOrderInfoBagVo.num : '暂无耗材包' }}</view>
					<view class="see" @click="moveTo">查看</view>
				</view> -->
			<view class="nursing" v-if="list.sofuQrCode">
				<view class="title" style="margin-bottom: 0;">
					<view class="titleIcon">
						<image src="../../../static/icon/order/2.png" mode=""></image>
					</view>
					<view class="titleMsg">快递码</view>
				</view>
				<view class="d-center">
					<image :src="list.sofuQrCode" mode="" style="width: 300rpx;height: 300rpx;"></image>
				</view>
			</view>
			<view class="nursing">
				<view class="title" style="margin-bottom: 0;">
					<view class="titleIcon">
						<image src="../../../static/icon/order/2.png" mode=""></image>
					</view>
					<view class="titleMsg">护理必备
					</view>
				</view>
				<view v-if="list.nurseOrderInfoBagVo">
					<view class="consume_title">{{list.nurseOrderInfoBagVo.name}} * {{list.nurseOrderInfoBagVo.num}}
					</view>
					<view class="consume_detail" v-for="(i,index) in list.nurseOrderInfoBagVo.consumables" :key="index">
						<view class="">{{i.bleName}}</view>
					</view>
				</view>
				<view v-else class="empty">
					无
				</view>
				<!-- 	<view class="consume_tip">
						温馨提示：首次上门服务时，需准备用户所购买全部耗材包提供患者，平台将自动为您结算耗材佣金！
					</view> -->
			</view>

			<view class="tip">
				<view class="title">
					<view class="titleIcon">
						<image src="../../../static/icon/order/3.png" mode=""></image>
					</view>
					<view class="titleMsg">医嘱</view>
				</view>
				<view class="tipImgs">
					<view class="tipImg" v-for="(item, index) in medicalOrder" :key="index" v-if="medicalOrder"
						style="background-color: rgba(243, 246, 246, 1);">
						<image :src="item" mode="aspectFit" @click="clickImg(index)" v-if="item"></image>
					</view>
					<!-- <view class="pastMsg" v-if="!medicalOrder">
					无
				</view> -->
				</view>
				<view class="past">
					<view class="pastTitle">过敏史</view>
					<view class="pastMsg">{{ healthFile.allergy ? healthFile.allergy : '无' }}</view>
				</view>
				<view class="past">
					<view class="pastTitle">遗传史</view>
					<view class="pastMsg">{{ healthFile.genetic ? healthFile.genetic : '无' }}</view>
				</view>
			</view>

			<view class="profit">
				<view class="title">
					<view class="titleIcon">
						<image src="../../../static/icon/order/4.png" mode=""></image>
					</view>
					<view class="titleMsg">备注</view>
				</view>
				<view class="pastMsg">{{ list.otherInfo ? list.otherInfo : '无' }}</view>
			</view>
			<!-- <block v-if="callIndex==0"> -->
			<view class="profit">
				<view class="title">
					<view class="titleIcon">
						<image src="../../../static/icon/order/5.png" mode=""></image>
					</view>
					<view class="titleMsg">服务收益</view>
				</view>
				<view class="profitMsg">
					<view class="profitTitle">{{ list.serviceName }}</view>
					<view class="profitPrice">￥{{ status==2? list.price : list.sonPrice }}</view>
				</view>

			</view>

			<!-- 待接单提示<view class="profitMsg">
					<view class="profitTitle">夜间费</view>
					<view class="profitPrice">￥{{list.nightServicePrice}}</view>
				</view>-->
			<view class="project" v-if="status == 2" style="margin-bottom:212rpx ;">
				<view class="title">
					<view class="titleMsg">上门须知</view>
				</view>
				<view class="pastMsg" style="margin-bottom: 16rpx;">1、接单后，护士在服务前请主动联系用户，自我介绍后确认用户基本信息与情况；</view>
				<view class="pastMsg" style="margin-bottom: 16rpx;">
					2、出门前请确认手机电量充足，系统信息同步确认,通讯正常。确保备齐各项操作中所用到的各类一次性用品、一次性耗材、护士证件。工作服整洁、无破损、无污迹、无褶皱；发型干净整洁、无异味、不怪异；胸牌整洁、无破损、佩戴左胸；出发前须再次与客户电话确认上门时间，提醒注意事项；
				</view>
				<view class="pastMsg" style="margin-bottom: 16rpx;">3、提前5~10分钟到达客户家门口,确认地址无误整理仪容,手机调至静音或振动;</view>
				<view class="pastMsg">
					4、入户后和客户说明来意，并出示健康码与护士证。点击开始服务，开启服务录音，检查室内环境是否具备开展服务的条件，向患者和患者家属介绍服务项目的相关流程和告知其可能引起的风险、并出示《上门服务知情同意书》由患者本人或者患者家属阅读后并签字,签字后方可开始进行服务。
				</view>
			</view>

			<!-- 待接单 -->
			<view class="end" v-if="status == 2"
				style="box-shadow: 0rpx -6rpx 8rpx 0rpx rgba(0, 0, 0, 0.03); position: fixed; bottom: 0;">
				<view class="into" style="width: 698rpx;" @click="takeOrder">去接单</view>
			</view>
			<!-- 带填写 -->
			<view class="end" style="justify-content: space-between;" v-else-if="status == 3 && !list.scheduleTime">
				<view class="todo" @click="call()">拨打电话</view>
				<view class="into">
					<biaofun-datetime-picker placeholder="填写时间" start="2000-02-03 00:00" end="2100-10-28 00:00"
						fields="minute" :show="show" style1="text-align: center;color:#ffffff"
						@change="changeDatetimePicker"></biaofun-datetime-picker>
				</view>
			</view>
			<!-- 已接单 -->
			<view class="end" style="justify-content: space-between;" v-else-if="status == 3 && list.scheduleTime">
				<view class="todo" @click="call()">拨打电话</view>
				<view class="into" @click="nurseWhetherItIsAHundredMeters()">开始服务</view>
			</view>
			<!-- 服务中  待审核-->
			<view class="end" style="justify-content: space-between;" v-else-if="status == 4">
				<view class="todo" @click="callLoto()">联系机构</view>
				<view class="into" v-if="!list.nursingRecordStatus || list.nursingRecordStatus == 3"
					@click="write(list)">
					{{list.showStatus ==0 ? '服务结束' :'填写报告'}}
				</view>
				<view class="into" v-if="list.nursingRecordStatus == 1" @click="seeReport()">查看报告</view>
			</view>
			<!-- 已完成 -->
			<view class="end" v-else-if="status == 5">
				<view class="into" @click="seeReport()">查看报告</view>
			</view>
			<!-- 取消-->
			<view class="end" v-else-if="status == 6">
				<!-- <view class="into" @click="callLoto()">联系机构</view> -->
			</view>
			<!-- 已退款 -->
			<view class="end" v-else-if="status == 7">
				<view class="into" @click="callLoto()">联系机构</view>
			</view>
			<!-- 异常 -->
			<view class="end" v-else-if="status == 8">
				<!-- <view class="into" @click="callLoto()" >联系机构</view> -->
			</view>
			<!-- 退款中 -->
			<view class="end" v-else-if="status == 9">
				<view class="into" @click="callLoto()">联系机构</view>
			</view>
			<!-- 拒绝 -->
			<view class="end" style="background-color:rgba(0, 0, 0,0) ;" v-else="status == 10">
				<!-- <view class="into" @click="callLoto()">联系机构</view> -->
			</view>
			<!-- </block> -->
		</view>
		<uni-confirm :show="confirmShow" :title="confirmTitle" :content="confirmContent" @cancel="bindBtn('cancel')"
			@confirm="bindBtn('confirm')"></uni-confirm>
		<Model :bol="flag" @handleFlag="handleFlag" :auth="auth"></Model>
		<uni-popup ref="popupHospital" type="center">
			<view class="sunui">
				<view class="hospitalBox">
					<view class="belong">
						所属医院：
					</view>
					<input class="inpt" type="text" v-model="hospitalAddress1" placeholder="请填写您的所属医院" />
					<button class="subBtn" @click="subBtn">确定</button>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="isStartRecord" type="center" :mask-click="false">
			<view class="d-j-center" style="width: 600rpx;">
				<view class="" style="background-color: #fff;padding: 8% 5% 8% 5%;width: 100%;">
					<view class="" style="font-size: 32rpx;">
						您的服务暂未结束，请选择继续录音：
					</view>
					<button class="record-l" @click="confirmRecord" style="margin-top: 5%;width: 60%;">确定</button>
				</view>
			</view>
		</uni-popup>
		<read-popup ref="readPopupRef" title="温馨提示" @confirm="moveTo">
			<view class="popup-content">
				<view class="popup-text">
					在抢单成功5分钟内电话联系顾客确认服务 时间、地址等信息是否正确，5分钟内未联 系顾客订单则会自动进入订单池，其他护士 即可抢单，此时该订单不再属于你的兼职服 务项目，若有问题请及时与平台工作人员取
					得联系
				</view>
				<view class="popup-text"> 
					若客户信息有误或无法联系用户，可联系平 台客服处理400-880-9120
				</view>
			</view>
		</read-popup>
	</skeleton>
</template>

<script>
	import readPopup from '@/components/common/model/read-popup.vue'
	import {
		selectNurseInfoCheckById
	} from '@/apis/certificate/certification.js'
	import uniPopup from '@/components/uni-ui/uni-popup/uni-popup.vue';
	import permision from "@/common/js/permission.js"
	import record from '@/mixins/record.vue';
	import {
		selectAllUrgencyLinkman
	} from '@/apis/security/index.js'
	import uniConfirm from '@/components/uni-ui/uni-confirm/uni-confirm.vue'
	import {
		selectMobileByUserId,
		selectHomeOrderInfo,
		selectOrderInfo,
		grabOrders,
		updateReceiptStatus,
		updateServeTime,
		sonOrderList,
		updateOrderStatus,
		nurseSelectOrderList,
		nurseWhetherItIsAHundredMeters,
		endOfServiceThreeHundredMeters
	} from '@/apis/order/index.js'
	import {
		selectConfigurationByServiceId
	} from '@/apis/nurse-report/index.js'
	import {
		debounce
	} from '@/common/js/throttle.js'
	import skeleton from '../../../components/common/skeleton/order-detail.vue'
	import biaofunDatetimePicker from '@/components/uni-ui/biaofun-datetime-picker/biaofun-datetime-picker.vue';
	import {
		requestAndroid,
		getLocation2,
		getLocation4
	} from '@/common/js/location.js'
	export default {
		components: {
			uniConfirm,
			skeleton,
			biaofunDatetimePicker,
			uniPopup,
			readPopup
		},
		mixins: [record],
		data() {
			return {
				callIndex: 0,
				hospitalAddress: '',
				hospitalAddress1: '',
				curItem: null,
				flag: false,
				auth: 'location',
				confirmType: '', //0 确认接单 1 确认开始服务 8添加紧急联系人
				confirmShow: false,
				confirmTitle: '',
				confirmContent: '',
				show: false,
				loading: true,
				list: '',
				healthFile: {},
				status: '', //订单状态
				medicalOrder: '', //医嘱图片
				number: '', //订单编号
				num: '', //1为短期订单 大于一为长期订单
				takeordertime: 0,
				page: {
					nurseId: this.$store.state.userInfo.id,
				},
				steps: [{
						msg: '联系用户',
						src: '../../../static/icon/order/tips1.png',
					},
					{
						msg: '上门服务',
						src: '../../../static/icon/order/tips2.png',
					},
					{
						msg: '填写报告',
						src: '../../../static/icon/order/tips3.png',
					},
					{
						msg: '服务完成',
						src: '../../../static/icon/order/tips4.png',
					},
				],
				service: [{
						title: '订单编号',
						value: []
					},
					{
						title: '服务时间',
						value: []
					},
					{
						title: '服务地址',
						value: [],
					},
					{
						title: '服务对象',
						value: []
					}
				],
				// 服务id
				serviceId: '',
				isHavePerson: 0,
				isRecord: false,
				isRecordList: [],
			}
		},
		onLoad(option) {
			// console.log(this.$store.state.userInfo);
			// console.log(option);
			this.status = Number(option.status)
			this.number = option.number //订单编号
			this.$store.commit('setcurItem', this.number)
			// console.log(this.number, '订单编号');
			// this.get()
			this.initContact()
			this.callIndex = option.callIndex
		},

		onShow() {
			console.log("onshow在这====112======")
			this.getStatus()
			this.get()
			uni.$on('selectTime', (res) => {
				this.form.scheduleTime = res.scheduleTime
				this.time = res.time
				// console.log(res,'时间');
			})
			this.initContact()
		},
		methods: {
			confirmRecord() {
				try {
					this.startRecord()
					this.getStatus()
					
					this.isRecord = this.$store.state.isRecord
					console.log('触发222222222222222222====',this.isRecord )
				} catch (e) {
					console.log("333333333",e)
					//TODO handle the exception
				}
				this.$refs.isStartRecord.close()
			},
			getRecordStatus() {
				// this.$refs.isStartRecord.open()
				this.getStatus()
				this.isRecord = this.$store.state.isRecord
				console.log('是否存在录音=========1 ', this.isRecord);
				console.log("录音状态",this.list.status,this.list.showStatus)
				let webView = this.$scope.$getAppWebview();
				console.log("触发了吗")
				// 服务结束的按钮，代表服务中，已经开始录音
				if (this.list.status == 4 && this.list.showStatus == 0) {
					if (this.isRecord == false) {
						console.log('重新开始录音',this.$refs.isStartRecord);
						this.$nextTick(()=>{
							this.$refs.isStartRecord.open()
						})
						//隐藏原始导航栏中的返回按钮
						webView.setStyle({
							titleNView: {
								autoBackButton: false
							}
						})
						console.log('执行完打开');
					} else if (this.isRecord == true) {
						console.log('正常不需要操作');
						webView.setStyle({
							titleNView: {
								autoBackButton: true
							}
						})
					}
				}
			},
			async subBtn() {
				console.log(this.hospitalAddress1);
				if (this.hospitalAddress1 == '') {
					//给提示
					uni.showToast({
						icon: 'none',
						title: '请填写您的所属医院'
					})
				} else {
					this.hospitalAddress = this.hospitalAddress1
					this.$store.commit('setHospitalAddress', this.hospitalAddress)
					this.$refs.popupHospital.close()
				}
			},
			//confirm 确定取消
			bindBtn(type) {
				// console.log(type)
				if (type == 'confirm') {
					console.log(type, 'confirm 确定')
					if (this.confirmType == 0) {
						this.confirmTakeOrder()
					} else if (this.confirmType == 8) {
						uni.navigateTo({
							url: '../../../pages/emergency-contact/list/list'
						})
						return
					} else {
						this.confirmStart()
					}
				} else {
					console.log('quxiao')
				}
				this.confirmShow = false
			},
			//图片预览
			clickImg(index) {
				let _this = this
				wx.previewImage({
					urls: _this.medicalOrder,
					current: _this.medicalOrder[index], // 当前显示图片的http链接，默认是第一个
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {},
				})
			},
			seeReport() {
				console.log("报告！！！！！！！",this.$store.state.userInfo.identity)
				if(this.$store.state.userInfo.identity == 3) {
					// #ifdef APP
					plus.nativeUI.toast('暂无报告可查看!')
					// #endif
					return
				}
				uni.navigateTo({
					url: '../../report/report-detaile/report-detaile?id=' + this.list.nursingRecordId
				})
			},
			//联系机构
			async callLoto() {
				let res = await this.handleJudgeCall()
				if (!res) {
					return
				}
				this.$store.dispatch('call')
			},
			//查看用户其他资料
			seeOther() {
				console.log(this.number, '1')
				uni.navigateTo({
					url: '../other-detaile/other-detaile?number=' + this.number
				})
			},
			//查看耗材详情
			// moveTo() {
			// 	if (this.list.nurseOrderInfoBagVo) {
			// 		uni.navigateTo({
			// 			url: '../consume-detail/consume-detail?number=' + this.number
			// 		})
			// 	} else {
			// 		// #ifdef APP-PLUS
			// 		plus.nativeUI.toast('暂无耗材包~')
			// 		// #endif
			// 		// #ifdef H5
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '暂无耗材包~'
			// 		})
			// 		// #endif
			// 		let data = this.list
			// 		uni.navigateTo({
			// 			url: '../consume-detail/consume-detail?number=' + this.number
			// 		})
			// 	}
			// },
			handleFlag(value) {
				this.flag = !!value
			},
			nurseWhetherItIsAHundredMeters() {
				getLocation4().then(res => {
					let data = {
						...res,
						orderNumber: this.number,
					}
					// 判断是否能够打卡
					nurseWhetherItIsAHundredMeters(data).then(res1 => {
						console.log("触发",res1)
						if (res1.success) {
							// return
							this.handleStart()
						}
				
				
					}).catch(err => {
						// #ifdef APP
						plus.nativeUI.toast(err.object)
						// #endif
					})
				})
			},
			async handleStart() {
				// 1、未完成订单 是否有医院
					// 2、是否存在紧急联系人
					// 3、是否录音
					// 4、是否定位
					// 5、判断是否签名
					
					// if (!this.$store.state.hasUncompleteOrder) {
					// 	// #ifdef APP
					// 	plus.nativeUI.toast('您有未完成订单，请填写护理报告完成订单!')
					// 	// #endif
					// 	return
					// }
					// var pages = getCurrentPages();
					// var currPage = pages[pages.length - 1]; //当前页面
					// console.log(currPage, '---------------')
					
					console.log("进入")
					// 紧急联系人
					// console.log('结果最后1次判断', this.isHavePerson, this.isHavePerson == 0);
					if (this.isHavePerson == 0) {
						this.confirmShow = true
						this.confirmContent = ''
						this.confirmTitle = '请添加紧急联系人！'
						this.confirmType = 8
						return
					}  else {
						this.confirmTitle = '是否确认开始服务?'
						this.confirmContent =
							'温馨提示：点击“确认”即表示已经上门服务，为了保证您的人身财产安全，平台将全程录音记录，切勿恶意点击！'
						this.confirmType = 1
					}
					
					// #ifdef APP-PLUS
					
					
					
					// 填写医院地址
					let id = this.$store.state.userInfo.id
					// console.log('id', id)
					let res = await selectNurseInfoCheckById({
						id,
					})
					// console.log(res)
					// console.log(this.$store.state.userInfo.identity)
					this.hospitalAddress = res.object.hospitalAddress
					this.$store.commit('setHospitalAddress', this.hospitalAddress)
					if (
						this.hospitalAddress1 == '' &&
						this.$store.state.userInfo.identity == 1
					) {
						if (
							res.object.hospitalAddress == '' ||
							res.object.hospitalAddress == null
						) {
							this.$refs.popupHospital.open()
							return
						}
					} else {
						// console.log(1)
					}
				
					// 定位权限
					// 没请求过权限，则需请求
					// 请求过权限，如果被拒绝，则文字提示
					
					// 录音授权
					let result = -1
					if (uni.getSystemInfoSync().platform === 'android') {
						result = await permision.requestAndroidPermission(
							'android.permission.RECORD_AUDIO'
						)
					} else {
						result = await permision.judgeIosPermission('record')
					}
					if (result != 1) {
						if (uni.getSystemInfoSync().platform == 'android') {
							// #ifdef APP
							plus.nativeUI.toast('请开启录音权限！')
							// #endif
							return
						} else {
							this.auth = 'luyin'
							this.handleFlag(true)
							return
						}
					}
					
					// 定位授权
					let loc = -1
					if (uni.getSystemInfoSync().platform == 'android') {
						loc = await permision.requestAndroidPermission(
							'android.permission.ACCESS_FINE_LOCATION'
						)
					} else {
						loc = await permision.judgeIosPermission('location')
					}
					
					if (loc != 1) {
						if (uni.getSystemInfoSync().platform == 'android') {
							// #ifdef APP
							plus.nativeUI.toast('请开启定位权限！')
							// #endif
							return
						} else {
							this.auth = 'location'
							this.handleFlag(true)
							return
						}
					}
					
					
					// #endif
					
					// 是否签名
					if (this.list.disclaimer) {
						if (this.list.isSign == -1) {
							this.getAssure()
							return
						}
					}
					this.toInfo()
				},
			toInfo: debounce(
				function() {
					if (this.list.nursingRecordId == null && [1].includes(this.$store.state.userInfo.identity)) {
						// 填写报告
						selectConfigurationByServiceId({
							serviceId: this.list.serviceId
						}).then(r => {
							// console.log(r, 33333333333333)
							uni.setStorageSync('reportTemplate', JSON.stringify(r.object))
							uni.navigateTo({
								url: '../../report/fill-in-report/report?number=' + this.number
							})
						})
					} else {
						console.log("在当前订单详情页面继续进行操作")
						this.start()
					}
				}, 1000, true
			),
			toInfol: debounce(
				function(item) {
					selectConfigurationByServiceId({
						serviceId: item.serviceId
					}).then(r => {
						uni.setStorageSync('reportTemplate', JSON.stringify(r.object))
						uni.navigateTo({
							url: '../../report/fill-in-report/report?number=' + this.number
						})
					})
				}, 1000, true
			),
			getAssure() {
				// console.log('免责协议')
				this.curItem = this.number
				uni.navigateTo({
					url: `../assure?number=${this.curItem}&img=${this.list.disclaimer}&serviceId=${this.list.serviceId}`
				})
			},
			handleCopy(v) {
				console.log(v)
				uni.setClipboardData({
					data: v,
					success: () => {
						console.log('success');
						uni.hideToast() //关闭自带的toast
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						});
					},
				})
			},
			async initContact() {
				let res = await selectAllUrgencyLinkman()
				if (res.success) {
					// console.log('紧急联系人调用接口', res)
					if (res.object.length > 0) {
						this.isHavePerson = 1
					}
				}
			},
			//开始服务
			async start() {
				this.confirmShow = true
				getLocation2()
				this.confirmType = 1
				this.confirmTitle = '是否确认开始服务?'
				this.confirmContent = "温馨提示：点击“确认”即表示已经上门服务，为了保证您的人身财产安全，平台将全程录音记录，切勿恶意点击！"
			},
			async handleJudgeCall() {
				if (uni.getSystemInfoSync().platform === 'android') {
					let result = await permision.requestAndroidPermission(
						"android.permission.CALL_PHONE") //1以获取 0未获取 -1权限禁止
					if (result != 1) {
						this.auth = 'call'
						this.handleFlag(true)
						return false
					}
				}
				return true
			},

			//确认开始服务
			async confirmStart() {
				// console.log('kaishi')
				// -----录音功能
				try {
					this.startRecord()
					this.get()
					// console.log('pppppp', this.isRecord);
					// this.isRecord = true
					console.log('11112---', this.isRecord);
					let webView = this.$scope.$getAppWebview();
					webView.setStyle({
						titleNView: {
							autoBackButton: true
						}
					})
				} catch (e) {
					//TODO handle the exception
				}
				let data = {
					hospitalAddress: this.hospitalAddress,
					number: this.number,
					status: 4,
					...this.$store.state.startServeLocation
				}
				// console.log(data, '614');
				let res = await updateReceiptStatus(data)
				// console.log('999999999999999999999', res)
				if (res.success) {
					// console.log('开始服务后的主状态变化', res)
					this.status = 4;
					// #ifdef APP
					plus.nativeUI.toast('您已开始服务')
					//#endif
					this.get()
				}
			},
			//服务前拨打电话
			async call() {
				let res1 = await this.handleJudgeCall()
				if (!res1) {
					return
				}
				let data = {
					number: this.number,
					userId: this.list.healthFile.userId,
					uuid: this.$store.state.uuid
				}
				let res = await selectMobileByUserId(data)
				if (res.success) {
					uni.makePhoneCall({
						phoneNumber: res.object
					})
				}
				console.log('拨打电话', res)
			},
			//填写护理报告
			async write(item) {
				console.log('item', item)
				// 状态为4和状态为服务结束
				if (item.status == 4 && item.showStatus == 0) {
 
					
					
					
					getLocation4().then(res=>{
						let data = {
							...res,
							orderNumber: this.number,
						}
						// 判断是否能够打卡
						endOfServiceThreeHundredMeters(data).then(res1=>{
							console.log("res1======",res1)
							if(res1.success) {
								// return
								this.stopRecord(this.updateOrderStatus)
								
								
							} 
							
							
						}).catch(err=>{
							// #ifdef APP
							plus.nativeUI.toast(err.object)
							// #endif
						})
					})
				} else if (item.status == 4 && item.showStatus == 1) {
					this.toInfol(item)
					this.get()
				}
				// 原来线上
				// uni.navigateTo({
				// 	url: '../../report/fill-in-report/fill-in-report?number=' + this.number
				// })
			},
			updateOrderStatus() {
				console.log("订单状态进入111111")
				updateOrderStatus({
					number: this.number,
				}).then(r => {
					console.log("订单状态进入22222", r)
					if (!r.success) {
						return
					}
					this.get()
					
				}).catch(err=>{
					console.log("时长不够60s")
					this.startRecord()
					this.getStatus()
				})
			},
			// 抢单
			async takeOrder() {
				// console.log('jiedan ')
				if (this.takeordertime > 0) {
					// #ifdef APP
					plus.nativeUI.toast('请勿重复点击')
					// #endif
					// uni.showToast({
					// 	icon:'none',
					// 	title:'请勿重复点击'
					// })
					return
				}
				this.confirmType = 0
				this.confirmShow = true
				this.confirmTitle = '是否确认接此订单?'
				this.confirmContent = "温馨提示：接单成功后，如未按时上门服务，平台将给予封号处罚！请仔细核对服务信息！"

			},
			//confirm 确认接单
			async confirmTakeOrder() {
				let res = await grabOrders({
					number: this.number
				})
				if (res.success) {
					this.takeordertime++
					// #ifdef APP
					plus.nativeUI.toast('接单成功')
					// #endif
					this.$nextTick(() => {
						// 在页面显示时打开弹窗
						this.$refs.readPopupRef.open()
					})
					// uni.navigateTo({
					// 	url: '../sub-order/sub-order?number=' + this.number + '&noReturn=true' + '&status=3'
					// })
				}
			},
			moveTo() {
				uni.redirectTo({
					url: '../sub-order/sub-order?number=' + this.number + '&noReturn=true' + '&status=3'
				})
			},
			//填写服务时间
			changeDatetimePicker(time) {
				let data = {
					data: time.f3 + ':00',
					number: this.number
				}
				this.timing(data)

			},
			//上传时间
			async timing(data) {
				let res = await updateServeTime(data)
				console.log(res, '选择时间');
				if (res) {
					plus.nativeUI.toast('您已填写时间')
					// uni.showToast({
					// icon:'success',
					// title:'您已填写时间！'
					// })
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 300)
				}

			},

			//获取订单详情
			async get() {
				let number = this.number
				// let res =await selectHomeOrderInfo({number})
				// if(number.length==13){
				// 	res =await selectHomeOrderInfo({number})
				// }else{
				// }
				let res = await selectOrderInfo({
					number
				})
				if (res.success) {
					this.loading = false
					this.list = res.object

					if (this.list.nightServicePrice == 0 || this.list.nightServicePrice == null) {
						this.list.nightServicePrice = 0
					} else {
						this.list.nightServicePrice = parseFloat(this.list.nightServicePrice).toFixed(2)
					}
					this.serviceId = this.list.serviceId
					this.healthFile = this.list.healthFile
					this.service[0].value[0] = this.number
					this.service[1].value = [res.object.scheduleTime]
					this.service[2].value = [res.object.address]
					if (res.object.healthFile.age) {
						this.service[3].value = [res.object.userName, (res.object.healthFile.sex || ''), res.object
							.healthFile
							.age + '岁'
						]
					} else {
						this.service[3].value = [res.object.userName, (res.object.healthFile.sex || ''), '']
					}

					// 后台返回的空 医嘱格式是[''],他们没改只能我们来改了
					if (!res.object.medicalOrder[0]) {
						this.medicalOrder = []
					} else {
						this.medicalOrder = res.object.medicalOrder
					}
					this.status = res.object.status
					console.log('---------', this.list);
					this.getRecordStatus()
				} else {

				}
			},
			//订单状态展示
			showStatus() {
				let list = this.list
				let status = this.status
				if (this.status == 3) {
					if (this.list.scheduleTime) {
						return '已接单'
					} else {
						return '待填写'
					}

				} else if (this.status == 4) {
					if (this.list.nursingRecordStatus == 1) {
						return '待审核'
					} else if (!this.list.nursingRecordStatus || this.list.nursingRecordStatus == 3) {
						return '服务中'
					}
				} else if (this.status == 5) {
					return '已完成'
				} else if (this.status == 6) {
					return '已取消'
				} else if (this.status == 7) {
					return '已退款'
				} else if (this.status == 8) {
					return '异常'
				} else if (this.status == 9) {
					return '退款中'
				} else if (this.status == 10) {
					return '已拒绝'
				}
			},
			//状态样式
			//状态样式
			statusStyle(status, index, item) {
				if (status == 3) {
					return `color:#FF6A00;`
				} else if (status == 4) {
					return `color:#FF6A00;`
				} else if (status == 5) {
					return `color:#333333`
				} else if (status == 6) {
					return `color:#999999`
				} else if (status == 7) {
					return `color:#333333`
				} else if (status == 8) {
					return `color:rgba(255, 79, 79, 1)`
				} else if (status == 9) {
					return `color:color:rgba(255, 79, 79, 1)`
				} else if (status == 10) {
					return `color:rgba(153, 153, 153, 1);`
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	//服务内容 地址位置换行
	.mabye {
		// max-width: 480rpx;
		word-wrap: break-all;
		word-break: normal;
		width: 80%;
	}
	.popup-content {
		padding-top: 32rpx;
		
		.popup-text {
			color: #374151;
			font-size: 28rpx;
			// font-weight: normal;
			line-height: 46rpx;
			margin-bottom: 32rpx;
		}
	}
	.content {
		background: linear-gradient(180deg, #3c8eff 0%, #f3f6f6 426rpx, rgba(243, 246, 246, 1) 100%);
		width: 100%;
		// min-height: 100vh;
		height: 100vh;
	}

	.steps {
		display: flex;
		width: 100%;
		height: 232rpx;
		box-sizing: border-box;

		.step {
			display: flex;

			.stepImg {
				width: 98rpx;
				height: 98rpx;
				margin: 0 auto;
				margin-bottom: 16rpx;

				image {
					width: 96rpx;
					height: 96rpx;
				}
			}

			.stepTitle {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #ffffff;
			}
		}

		image {
			width: 90rpx;
			height: 90rpx;
			margin-right: 20rpx;
		}

		.status {
			font-size: 40rpx;
			font-weight: 500;
			color: #ffffff;
			line-height: 56rpx;
		}

		.status_msg {
			font-size: 24rpx;
			color: #ffffff;
			line-height: 40rpx;
		}
	}

	.project {
		width: 698rpx;
		background: #ffffff;
		border-radius: 20rpx;
		margin: 0 auto;
		padding: 44rpx 24rpx;
		box-sizing: border-box;
		margin-bottom: 16rpx;

		.other {
			position: absolute;
			width: 120rpx;
			height: 42rpx;
			background: #ffffff;
			border-radius: 4rpx;
			border: 1rpx solid #3c8eff;
			line-height: 42rpx;
			text-align: center;
			font-size: 24rpx;
			color: #3c8eff;
			float: right;
			right: 0 !important;

			&.my {
				// width: 126rpx;
				// margin-left: 20rpx;
				// float:none;
			}
		}
	}

	.title {
		line-height: 48rpx;
		display: flex;
		margin-bottom: 32rpx;
		position: relative;

		.type {
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #ff4f4f;
			position: absolute;
			right: -40rpx;
		}

		.titleMsg {
			font-size: 40rpx;
			width: 500rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 48rpx;
			margin-left: 8rpx;
			word-wrap: break-word;
			word-break: normal;
		}

		.profitPrice {
			position: absolute;
			right: 0;
		}
	}

	.titleIcon {
		width: 48rpx;
		height: 48rpx;

		// background-color: #3C8EFF;
		image {
			width: 48rpx;
			height: 48rpx;
		}
	}

	.nursing {
		width: 698rpx;
		background: #ffffff;
		border-radius: 20rpx;
		margin: 0 auto;
		margin-bottom: 16rpx;
		padding: 44rpx 24rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.consume_title {
			width: 540rpx;
			margin: 16rpx 0;
			font-size: 28rpx;
			font-weight: 400;
		}

		.consume_detail {
			box-sizing: border-box;
			width: 100%;
			margin: 0 auto 16rpx;
			background: rgba(0, 0, 0, 0.03);
			border-radius: 20rpx;
			font-weight: 400;
			font-size: 24rpx;
			padding: 22rpx 26rpx;
		}

		.empty {
			margin-top: 12rpx;
		}

		.consume_tip {
			font-size: 24rpx;

			color: rgba(234, 32, 39, 1);
			margin-top: 6rpx;
			// margin: 0 auto;
		}

		.nursingP {
			display: flex;
			justify-content: space-between;
		}
	}

	.see {
		width: 160rpx;
		height: 42rpx;
		background: #ffffff;
		border-radius: 4px;
		border: 1rpx solid #3c8eff;
		left: 42rpx;
		text-align: center;
	}

	.tip {
		width: 698rpx;
		background: #ffffff;
		border-radius: 20rpx;
		margin: 0 auto;
		margin-bottom: 16rpx;
		padding: 44rpx 24rpx;
		box-sizing: border-box;

		.tipImgs {
			margin-top: 36rpx;
			display: flex;
			justify-content: flex-start;
			box-sizing: border-box;

			.tipImg {
				width: 152rpx;
				height: 152rpx;
				// background: #D8D8D8;
				border: 1rpx solid #979797;
				box-sizing: border-box;
				margin-right: 14rpx;

				image {
					width: 152rpx;
					height: 152rpx;
				}
			}
		}

		.past {
			margin-top: 32rpx;

			.pastTitle {
				height: 44rpx;
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: rgba(0, 0, 0, 0.87);
				line-height: 44rpx;
				margin-bottom: 16rpx;
			}
		}
	}

	.pastMsg {
		width: 650rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(0, 0, 0, 0.6);
		line-height: 40rpx;
	}

	.ps {
		width: 698rpx;
		// height: 208rpx;
		margin: 0 auto;
		margin-bottom: 16rpx;
		background-color: #ffffff;
		padding: 44rpx 24rpx;
		box-sizing: border-box;

		.psMsg {
			width: 650rpx;
			margin-top: 32rpx;
		}
	}

	.profit {
		width: 698rpx;
		margin: 0 auto;
		margin-bottom: 16rpx;
		background-color: #ffffff;
		padding: 44rpx 24rpx;
		box-sizing: border-box;
		border-radius: 20rpx;

		.profitMsg {
			display: flex;
			justify-content: space-between;
			margin-top: 32rpx;
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.6);
		}
	}

	.end {
		width: 100%;
		height: 212rpx;
		background: #ffffff;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding: 0 38rpx;
		box-sizing: border-box;
		box-shadow: 0rpx -6rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);

		.into {
			width: 315rpx;
			height: 96rpx;
			background: #3c8eff;
			font-size: 36rpx;
			color: #ffffff;
			line-height: 96rpx;
			text-align: center;
			border-radius: 8rpx;
		}
	}

	.todo {
		width: 315rpx;
		height: 96rpx;
		background: #ffffff;
		border: 2rpx solid #3C8EFF;
		box-sizing: border-box;
		position: relative;
		margin-right: 28rpx;
		line-height: 96rpx;
		text-align: center;
		border-radius: 8rpx;
		color: #3C8EFF;
		font-size: 36rpx;
	}

	.sunui {
		border-radius: 5rpx;
		position: relative;
		width: 650rpx;
		height: 300rpx;
		background-color: #ffffff;
		margin: 0 auto;
		padding: 15rpx 15rpx;
		display: flex;
		justify-content: center;
		align-items: center;

		.hospitalBox {
			width: 100%;

			.belong {
				font-size: 32rpx;
			}

			.inpt {
				margin-top: 12rpx;
				background-color: #FFF;
				width: 100%;
				height: 60rpx;
				border-radius: 5rpx;
				// margin-left: 30rpx;
				color: #333;
				border: #93a1a1 2rpx solid;
			}

			.subBtn {
				display: flex;
				justify-content: center;
				border-radius: 5rpx;
				width: 150rpx;
				height: 65rpx;
				background-color: #528df5;
				color: #fff;
				align-items: center;
				line-height: 55rpx;
				margin: 25rpx auto;
			}
		}


	}

	.record-l {
		background: #3c8eff;
		color: #ffffff;
		text-align: center;
		font-size: 28rpx;
		border-radius: 8rpx;
	}
</style>